/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.objects;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Organization object
 * @author Kyle Parker, University Computing Services
 */
public class Organization implements Comparable<Organization> {
	private String address;
	private String category;
	private String degree;
	private String displayName;
	private String dues;
	private String emailAddress;
	private String error;
	private String founded;
	private String memberCount;
	private String membershipReq;
	private String organizationDesc;
	private String organizationID;
	private String organizationName;
	private String phone;
	private String programOption;
	private String programType;
	private URL shareURL;
	private String website;

	public String getAddress() {		
		return address;
	}
	public void setAddress(String value) {
		this.address = value.trim();
	}
	
	public String getCategory() {		
		return category;
	}
	public void setCategory(String value) {
		this.category = value.trim();
	}
	
	public String getDegree() {		
		return degree;
	}
	public void setDegree(String value) {
		this.degree = value.trim();
	}
	
	public String getDisplayName() {		
		return displayName;
	}
	public void setDisplayName(String value) {
		this.displayName = value.trim();
	}
	
	public String getDues() {		
		return dues;
	}
	public void setDues(String value) {
		this.dues = value.trim();
	}
	
	public String getEmailAddress() {		
		return emailAddress;
	}
	public void setEmailAddress(String value) {
		this.emailAddress = value.trim();
	}
	
	public String getError() {		
		return error;
	}
	public void setError(String value) {
		this.error = value.trim();
	}
	
	public String getFounded() {		
		return founded;
	}
	public void setFounded(String value) {
		this.founded = value.trim();
	}

	public String getOrganizationDesc() {
		return organizationDesc;
	}
	public void setOrganizationDesc(String value) {
		this.organizationDesc = value.trim();
	}
	
	public String getMemberCount() {		
		return memberCount;
	}
	public void setMemberCount(String value) {
		this.memberCount = value.trim();
	}
	
	public String getMembershipReq() {		
		return membershipReq;
	}
	public void setMembershipReq(String value) {
		this.membershipReq = value.trim();
	}
	
	public String getOrganizationName() {		
		return organizationName;
	}
	public void setOrganizationName(String value) {
		this.organizationName = value.trim();
	}
	
	public String getOrganizationID() {		
		return organizationID;
	}
	public void setOrganizationID(String value) {
		this.organizationID = value;
	}

	public String getPhone() {
		return phone;
	}
	public void setPhone(String value) {
		this.phone = value.trim();
	}

	public String getProgramOption() {
		return programOption;
	}
	public void setProgramOption(String value) {
		this.programOption = value.trim();
	}

	public String getProgramType() {		
		return programType;
	}
	public void setProgramType(String value) {
		this.programType = value.trim();
	}
	
	public URL getShareURL() {
		return shareURL;
	}	
	public void setShareURL(String value) {
		try  {
			this.shareURL = new URL(value);
		} catch (MalformedURLException e) {
			this.shareURL = null;
		}
	}

	public String getWebsite() {		
		return website;
	}
	public void setWebsite(String value) {
		this.website = value.trim();
	}
	
	public Organization copy() {
		Organization copy = new Organization();
		copy.address = address;
		copy.category = category;
		copy.degree = degree;
		copy.displayName = displayName;
		copy.dues = dues;
		copy.emailAddress = emailAddress;
		copy.error = error;
		copy.founded = founded;
		copy.memberCount = memberCount;
		copy.membershipReq = membershipReq;
		copy.organizationDesc = organizationDesc;
		copy.organizationID = organizationID;
		copy.organizationName = organizationName;
		copy.programOption = programOption;
		copy.programType = programType;
		copy.phone = phone;
		copy.shareURL = shareURL;
		copy.website = website;
		return copy;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result + ((category == null) ? 0 : category.hashCode());
		result = prime * result + ((degree == null) ? 0 : degree.hashCode());
		result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
		result = prime * result + ((dues == null) ? 0 : dues.hashCode());
		result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
		result = prime * result + ((error == null) ? 0 : error.hashCode());
		result = prime * result + ((founded == null) ? 0 : founded.hashCode());
		result = prime * result + ((memberCount == null) ? 0 : memberCount.hashCode());
		result = prime * result + ((membershipReq == null) ? 0 : membershipReq.hashCode());
		result = prime * result + ((organizationDesc == null) ? 0 : organizationDesc.hashCode());
		result = prime * result + ((organizationID == null) ? 0 : organizationID.hashCode());
		result = prime * result + ((organizationName == null) ? 0 : organizationName.hashCode());
		result = prime * result + ((programOption == null) ? 0 : programOption.hashCode());
		result = prime * result + ((programType == null) ? 0 : programType.hashCode());
		result = prime * result + ((phone == null) ? 0 : phone.hashCode());
		result = prime * result + ((shareURL == null) ? 0 : shareURL.hashCode());
		result = prime * result + ((website == null) ? 0 : website.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) { return true; }
		
		if (obj == null) { return false; }
		
		if (getClass() != obj.getClass()) { return false; }
		
		Organization other = (Organization) obj;
		
		if (address == null)  {
			if (other.address != null) { return false; }
		} else if (!address.equals(other.address)) { return false; }
		
		if (category == null)  {
			if (other.category != null) { return false; }
		} else if (!category.equals(other.category)) { return false; }
		
		if (degree == null)  {
			if (other.degree != null) { return false; }
		} else if (!degree.equals(other.degree)) { return false; }
		
		if (displayName == null) {
			if (other.displayName != null) { return false; }
		} else if (!displayName.equals(other.displayName)) { return false; }
		
		if (dues == null) {
			if (other.dues != null) { return false; }
		} else if (!dues.equals(other.dues)) { return false; }
		
		if (emailAddress == null) {
			if (other.emailAddress != null) { return false; }
		} else if (!emailAddress.equals(other.emailAddress)) { return false; }
		
		if (error == null) {
			if (other.error != null) { return false; }
		} else if (!error.equals(other.error)) { return false; }
		
		if (founded == null) {
			if (other.founded != null) { return false; }
		} else if (!founded.equals(other.founded)) { return false; }
		
		if (memberCount == null) {
			if (other.memberCount != null) { return false; }
		}  else if (!memberCount.equals(other.memberCount)) { return false; }
		
		if (membershipReq == null) {
			if (other.membershipReq != null) { return false; }
		} else if (!membershipReq.equals(other.membershipReq)) { return false; }
		
		if (organizationDesc == null) {
			if (other.organizationDesc != null) { return false; }
		} else if (!organizationDesc.equals(other.organizationDesc)) { return false; }
		
		if (organizationID == null) {
			if (other.organizationID != null) { return false; }
		} else if (!organizationID.equals(other.organizationID)) { return false; }
		
		if (organizationName == null) {
			if (other.organizationName != null) { return false; }
		} else if (!organizationName.equals(other.organizationName)) { return false; }
		
		if (programOption == null) {
			if (other.programOption != null) { return false; }
		} else if (!programOption.equals(other.programOption)) { return false; }
		
		if (programType == null) {
			if (other.programType != null) { return false; }
		} else if (!programType.equals(other.programType)) { return false; }
		
		if (phone == null) {
			if (other.phone != null) { return false; }
		} else if (!phone.equals(other.phone)) { return false; }
		
		if (shareURL == null) {
			if (other.shareURL != null) { return false; }
		} else if (!shareURL.equals(other.shareURL)) { return false; }
		
		if (website == null) {
			if (other.website != null) { return false; }
		}  else if (!website.equals(other.website)) { return false; }
		
		return true;
	}

	public int compareTo(Organization another)  {
		if (another == null) return 1; 
		return another.organizationName.compareTo(organizationName);
	}
}
